//
//  CCRouter.m
//  Activity
//
//  Created by its on 15/5/8.
//  Copyright (c) 2015年 coco. All rights reserved.
//

#import "CCRouter.h"
#import "CCRPhoneViewController.h"
#import "CCRSMSCodeViewController.h"
#import "CCRNickViewController.h"
#import "CCRSMSViewModel.h"
#import "CCRNickViewModel.h"
#import "CCADetailViewController.h"
#import "CCDetailViewModel.h"
#import "CCCommentViewModel.h"
#import "CCCommentModel.h"
#import "CCCommentViewController.h"
#import "CCLoginViewController.h"
#import "CCLoginViewModel.h"
#import <SPInteractivePopNavigationController/SPInteractivePopNavigationController.h>
@interface CCRouter()
@property (nonatomic, strong) UINavigationController *navi;
@end
@implementation CCRouter

+(void) routerWithURL:(NSString *)path param:(id)param {
  if ([path isEqualToString:@"rphone"]) { // 进入填写手机号码
    
    CCRPhoneViewController *vc = [[CCRPhoneViewController alloc] initWithViewModel:param];
    [[[CCRouter shareInstance] navi] pushViewController:vc animated:YES];
    
  } else if ([path isEqualToString:@"rsms"]){   // 进入填写手机验证码界面
    
    CCRSMSViewModel *model = [[CCRSMSViewModel alloc] initWithPhone:param[@"phone"]];
    CCRSMSCodeViewController *vc = [[CCRSMSCodeViewController alloc] initWithViewModel:model];
    [[[CCRouter shareInstance] navi] pushViewController:vc animated:YES];
    
  } else if([path isEqualToString:@"ruser"]) {  // 进入设置用户名和密码的界面
    
    CCRNickViewModel *viewModel = [[CCRNickViewModel alloc] init];
    CCRNickViewController *vc = [[CCRNickViewController alloc] initWithViewModel:viewModel];
    [[[CCRouter shareInstance] navi] pushViewController:vc animated:YES];
    
  } else if ([path isEqualToString:@"detail"]) {  // 进入活动详情界面
    
    CCDetailViewModel *viewModel = [[CCDetailViewModel alloc] initWithActivityID:param[@"id"] activityAuthor:param[@"authorId"]];
    CCADetailViewController *vc = [[CCADetailViewController alloc] initWithViewModel:viewModel];
    vc.hidesBottomBarWhenPushed = YES;
    [[[CCRouter shareInstance] navi] pushViewController:vc animated:YES];
    
  } else if ([path isEqualToString:@"map"]) { // 从详情界面进入地图界面
    
  } else if ([path isEqualToString:@"comment"]) { // 进入评论界面
    CCCommentModel *model = [[CCCommentModel alloc] init];
    CCCommentViewModel *viewModel = [[CCCommentViewModel alloc] initWithModel: model];
    viewModel.activityid = param[@"id"];
    viewModel.activityTitle = param[@"activityTitle"];
    viewModel.activityAuthor = param[@"activityAuthor"];
    CCCommentViewController *vc = [[CCCommentViewController alloc] initWithViewModel:viewModel];
    [[[CCRouter shareInstance] navi] pushViewController:vc animated:YES];
    
  } else if ([path isEqualToString:@"talk"]) {  // 进入讨论界面
    
  } else if ([path isEqualToString:@"login"]) {
    UIViewController *viewcontroller = param[@"controller"];
    CCLoginViewModel *model = [[CCLoginViewModel alloc] init];
    CCLoginViewController *vc = [[CCLoginViewController alloc] initWithViewModel:model];
    SPInteractivePopNavigationController *navi = [[SPInteractivePopNavigationController alloc] initWithRootViewController:vc];
    navi.navigationBar.translucent = NO;
    navi.navigationBar.barTintColor = RGB(46, 169, 56, 1);
    navi.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
    
    [viewcontroller presentViewController:navi animated:YES completion:^{
    }];
  }
}

+ (id) shareInstance {
  static dispatch_once_t onceToken;
  static CCRouter *router;
  dispatch_once(&onceToken, ^{
    router = [[CCRouter alloc] init];
  });
  return router;
}

+ (void) setNavigationController:(id) navi {
  CCRouter *router = [CCRouter shareInstance];
  router.navi = navi;
}
@end
